//
//  HCFindGoodsDetailView.m
//  HappyChildren
//
//  Created by jiayibai-02por on 2017/6/12.
//  Copyright © 2017年 WillyZhao. All rights reserved.
//

#import "HCFindGoodsDetailView.h"

@interface HCFindGoodsDetailView()

@property (nonatomic, strong) UILabel *goodsDescrip; //商品描述
@property (nonatomic, strong) UIButton *collectButton; //收藏按钮
@property (nonatomic, strong) UILabel *promptLabel; //积分
@property (nonatomic, strong) UILabel *inventory;//库存
@property (nonatomic, strong) UILabel *sales; //销量
@property (nonatomic, strong) UILabel *freightNum; //运费
@property (nonatomic, strong) UILabel *address; //地址

@end

@implementation HCFindGoodsDetailView

- (instancetype)initWithFrame:(CGRect)frame {

    if (self = [super initWithFrame:frame]) {
        
        [self initializeView];
    }
    return self;
}

- (void)initializeView {

    self.goodsDescrip = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, Screen_width-50-30, YBKAdaptiveH(64))];
    self.goodsDescrip.numberOfLines = 0;
    self.goodsDescrip.textColor = [UIColor darkGrayColor];
    self.goodsDescrip.font = [UIFont systemFontOfSize:14];
    self.goodsDescrip.text = @"";
    [self addSubview:self.goodsDescrip];
    
    self.collectButton = [[UIButton alloc] initWithFrame:CGRectMake(Screen_width-50, 0, 50, 50)];
    [self.collectButton setImage:[UIImage imageNamed:@"find_collect_img"] forState:UIControlStateNormal];
    [self.collectButton addTarget:self action:@selector(collectAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.collectButton];
    
    self.promptLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(self.goodsDescrip.frame)+5, 100, 16)];
    self.promptLabel.textColor = [UIColor redColor];
    self.promptLabel.font = [UIFont systemFontOfSize:14];
    self.promptLabel.text = @"积分 999";
    [self addSubview:self.promptLabel];
    
    self.inventory = [[UILabel alloc] initWithFrame:CGRectMake(Screen_width-80, CGRectGetMinY(self.promptLabel.frame), 70, 14)];
    self.inventory.font = [UIFont systemFontOfSize:11];
    self.inventory.textColor = [UIColor lightGrayColor];
    self.inventory.layer.borderColor = [UIColor lightGrayColor].CGColor;
    self.inventory.layer.borderWidth = 0.5;
    self.inventory.layer.cornerRadius = 2.0;
    self.inventory.textAlignment = NSTextAlignmentCenter;
    [self addSubview:self.inventory];
    
    self.sales = [[UILabel alloc] initWithFrame:CGRectMake(Screen_width-80, CGRectGetMaxY(self.inventory.frame)+5, 70, 14)];
    self.sales.font = [UIFont systemFontOfSize:11];
    self.sales.textColor = [UIColor lightGrayColor];
    self.sales.layer.borderColor = [UIColor lightGrayColor].CGColor;
    self.sales.layer.borderWidth = 0.5;
    self.sales.layer.cornerRadius = 2.0;
    self.sales.textAlignment = NSTextAlignmentCenter;
    [self addSubview:self.sales];
    
    self.inventory.text = @"库存:0";
    self.sales.text = @"销量:0";
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(self.sales.frame)+15, Screen_width-30, 1)];
    line.backgroundColor = [UIColor lightGrayColor];
    [self addSubview:line];
    
    UILabel * freightLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(line.frame)+10, 30, 14)];
    freightLabel.font = [UIFont systemFontOfSize:10];
    freightLabel.textColor = [UIColor grayColor];
    freightLabel.text = @"运费:";
    [self addSubview:freightLabel];
    
    UILabel *addressLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(freightLabel.frame) + 10, 30, 40)];
    addressLabel.font = [UIFont systemFontOfSize:10];
    addressLabel.textColor = [UIColor grayColor];
    addressLabel.text = @"送至:";
    [self addSubview:addressLabel];
    
    self.freightNum = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(freightLabel.frame), CGRectGetMinY(freightLabel.frame), 100, 14)];
    self.freightNum.textColor = [UIColor darkGrayColor];
    self.freightNum.font = [UIFont systemFontOfSize:10];
    self.freightNum.text = @"10000";
    [self addSubview:self.freightNum];
    
    UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(addressLabel.frame), CGRectGetMinY(addressLabel.frame), Screen_width-60, 40)];
    [self addSubview:bottomView];
    
    self.address = [[UILabel alloc] initWithFrame:bottomView.bounds];
    self.address.textColor = [UIColor darkGrayColor];
    self.address.font = [UIFont systemFontOfSize:12];
    self.address.numberOfLines = 0;
    self.address.text = @"四川成都";
    [bottomView addSubview:self.address];
    
    bottomView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickBottomView)];
    [bottomView addGestureRecognizer:tap];
    
    UIView *line1 = [[UIView alloc] initWithFrame:CGRectMake(0, self.frame.size.height-10, Screen_width, 10)];
    line1.backgroundColor = YBKRGBCOLOR(240, 240, 240, 1);
    [self addSubview:line1];
}

- (void)setDataDic:(NSDictionary *)dataDic {

    _dataDic =dataDic;
    if (dataDic.count > 0) {
        
        self.freightNum.text = [NSString stringWithFormat:@"%@",[dataDic objectForKey:@"freight"]];
        self.goodsDescrip.text = [dataDic objectForKey:@"name"];
        self.promptLabel.text = [NSString stringWithFormat:@"积分 %@",[dataDic objectForKey:@"price"]];
        if (![PublicFunction isNull:[dataDic objectForKey:@"total_num"]]) {
            
            self.inventory.text = [NSString stringWithFormat:@"库存:%@",[dataDic objectForKey:@"total_num"]];
        }
        else {
        
            self.inventory.text = @"库存:0";
        }
        if ([PublicFunction isNull:[dataDic objectForKey:@"num"]]) {
            
            self.sales.text = [NSString stringWithFormat:@"销量:%@",[dataDic objectForKey:@"num"]];
        }
        else {
        
            self.sales.text = @"销量:0";
        }
    }
}

- (void)clickBottomView {

    if (self.didClickAddressViewBlock) {
        
        self.didClickAddressViewBlock();
    }
}

- (void)collectAction:(UIButton *)sender {

    if (self.didClickCollectButtonBlock) {
        
        self.didClickCollectButtonBlock();
    }
}

- (void)setAddressData:(NSDictionary *)addressData {

    _addressData = addressData;
    if (addressData) {
        
        self.address.text = addressData[@"address"];
    }
}

@end
